<?php
/**
 * 佣金管理
 * @author Administrator
 */
class commission extends admin{
    public function __construct(){
        parent::__construct();
        array_walk_recursive($_GET,'safe_filter');
        array_walk_recursive($_POST,'safe_filter');
    }
    
    //佣金列表
    public function index(){
        if(IS_AJAX){
            $start = isset($_GET['start'])&&!empty($_GET['start'])?strtotime($_GET['start']):0;
            $end = isset($_GET['end'])&&!empty($_GET['end'])?strtotime($_GET['end']):NOW;
            $where ='where time between '.$start.' and '.$end;
            $mo=$_GET['mobile'];
            if($mo!=''){
                $res=db()->getAll("select id from x_user where mobile like '%$mo%'");
                if($res){
                    $uid='';
                    foreach ($res as $v){
                        $uid.=$v['id'].",";
                    }
                    $uid .=0;
                    $where .= " and uid in ($uid)";
                }
            }
            $total=db()->getOne('select count(*) from x_commission '.$where);
            $pagesize = C('PAGE_SIZE');
            if (isset($_GET['p']) && (int) $_GET['p'] > 0) $p = (int) $_GET['p'];
            else $p = 1;
            $limit=' limit '.($p-1)*$pagesize.','.$pagesize;
            $list=db()->getAll("select c.*,u.real_name,u.mobile from x_commission as c left join x_user as u on c.uid=u.id $where order by id DESC $limit");
            if (!$list) $list=array();
            $page = array('total' => $total,'pagesize' =>$pagesize,'curpage' => $p);
            $this->ajaxReturn(array('status'=>1,'data'=>$list,'page'=>$page));
        }else{
            $tpl=$this->Template();
            $tpl->display();
        }
        
    }
    
    //添加用户
    public function add(){
        if(IS_AJAX){
            
        }else{
            $tpl=$this->Template();
            $tpl->display();
        }
    }
    //编辑用户
    public function edit(){
        if(IS_AJAX){
    
        }else{
            $id=(int)$_GET['id'];
            $vo=db()->getRow('select * from x_commission where id='.$id);
            $tpl=$this->Template();
            $tpl->assign('vo',$vo);
            $tpl->display();
        }
    }
    //删除用户
    public function del(){
        if(IS_AJAX){
           $id=$_GET['id'];
           if($id<=0) $this->ajaxReturn(array('status'=>'n','info'=>'参数错误'));
           $affert_rows=db()->delete('x_commission','id='.$id);
           if($affert_rows) $this->ajaxReturn(array('status'=>'y','info'=>'删除成功'));
           else $this->ajaxReturn(array('status'=>'n','info'=>'删除失败'));
        }
    }
    
}